package com.huafeng.attendance.service.impl;

import java.util.List;
import com.ws.commons.hqlExec.service.HqlExecuteService;
import com.ws.commons.keyGenerate.service.KeyGenerator;
import com.huafeng.attendance.bean.Attendance;
import com.huafeng.attendance.dao.AttendanceDao;
import com.huafeng.attendance.service.AttendanceService;

/**
 * Attendance Service控制实现类
 * @author waysoft
 */
public class AttendanceServiceImpl implements AttendanceService {
	private AttendanceDao attendanceDao;
		
	private HqlExecuteService hqlExecuteService;

	/**
	 * 增加gr20报表模版列表
	 * @param attendance
	 */
	public void save(Attendance attendance) {
		int key = KeyGenerator.getInstance().getNextKey("attendance");
		attendance.setAttend_id(key);
		this.attendanceDao.save(attendance);
	}
	
	/**
	 * 修改gr20报表模版列表
	 * @param attendance
	 */
	public void update(Attendance attendance) {
		this.attendanceDao.update(attendance);
	}
	
	/**
	 * 根据本表主键删除
	 * @param attend_id 主键值
	 */
	public void deleteByAttend_id(Integer attend_id) throws Exception{
		this.deleteByAttend_id(new Integer[]{attend_id});
	}

	/**
	 * 根据本表主键批量删除
	 * @param attend_ids 主键数组
	 */
	public void deleteByAttend_id(Integer[] attend_ids) throws Exception{
		if (attend_ids != null && attend_ids.length > 0) {
			String idstr = "";
			for (int i = 0; i <  attend_ids.length; i++) {
				idstr += attend_ids[i] + ",";
			}
			idstr = idstr.substring(0, idstr.length() - 1);
			String hql="delete Attendance attendance where attendance.attend_id in("+idstr+")";
			hqlExecuteService.executeUpdate(hql);
		}
	}
	
	
	/**
	 * 根据主键查询唯一对象
	 * @param attend_id 主键值
	 */
	public Attendance findByAttend_id(Integer attend_id) {
		return this.attendanceDao.findByAttend_id(attend_id);
	}

	
	public void setAttendanceDao(AttendanceDao attendanceDao) {
		this.attendanceDao = attendanceDao;
	}
	
	public void setHqlExecuteService(HqlExecuteService hqlExecuteService) {
		this.hqlExecuteService = hqlExecuteService;
	}
}
